define(["require", "exports"], function (require, exports) {
    "use strict";
    var Path = "widgets";
    var CameraDebugger = (function () {
        function CameraDebugger(params) {
            this.viewer = null;
            this.container = null;
            this.top = 0;
            this.left = 0;
            this.camera = null;
            this.contentJquery = null;
            this.callback = null;
            this.posXYZ = null;
            this.posLonLat = null;
            this.posHeight = null;
            this.dirXYZ = null;
            this.viewer = params["viewer"];
            if (this.viewer == null)
                return;
            this.camera = this.viewer.camera;
            this.container = params["container"] == null ? this.viewer._container : params["container"];
            this.top = params["top"] == null ? 0 : params["top"];
            this.left = params["left"] == null ? 0 : params["left"];
            this.callback = params["callback"];
            this.setStyle();
            this.getFrameHtml(this.callback);
        }
        CameraDebugger.prototype.getFrameHtml = function (callback) {
            (function (that) {
                var url = Path + "/CameraDebugger/Widget.html";
                $.ajax(url, {
                    dataType: "text",
                    success: function (data) {
                        that.contentJquery = $(data);
                        that.contentJquery.css("top", that.top);
                        that.contentJquery.css("left", that.left);
                        that.contentJquery.appendTo(that.container);
                        that.initEvent();
                        if (typeof callback == "function") {
                            callback();
                        }
                    }
                });
            })(this);
        };
        CameraDebugger.prototype.setStyle = function (url) {
            var styleID = "CameraDebugger-css";
            if ($("#" + styleID).length > 0) {
                return;
            }
            var linkTag = $('<link id="' + styleID + '" rel="stylesheet" href="' + Path + "/CameraDebugger/css/style.css" + '"/>');
            $($('head')[0]).append(linkTag);
        };
        CameraDebugger.prototype.initEvent = function () {
            var that = this;
            this.viewer.scene.postRender.addEventListener(function () {
                var camera = this.camera;
                this.posXYZ = camera.position.x + "  " + camera.position.y + "  " + camera.position.z;
                var cartographic = Cesium.Cartographic.fromCartesian(camera.position);
                this.posLonLat = Cesium.Math.toDegrees(cartographic.longitude) + "  " + Cesium.Math.toDegrees(cartographic.latitude);
                this.posHeight = cartographic.height;
                this.dirXYZ = camera.direction.x + "  " + camera.direction.y + "  " + camera.direction.z;
                this.contentJquery.find(".positionXYZ input").val(this.posXYZ);
                this.contentJquery.find(".positionLonLat input").val(this.posLonLat);
                this.contentJquery.find(".positionHeight input").val(this.posHeight);
                this.contentJquery.find(".directionXYZ input").val(this.dirXYZ);
            }.bind(this));
            this.contentJquery.find(".outputBtn").on("click", function () {
                console.log("posXYZ: " + this.posXYZ);
                console.log("posLonLat: " + this.posLonLat);
                console.log("posHeight: " + this.posHeight);
                console.log("dirXYZ: " + this.dirXYZ);
            }.bind(that));
        };
        return CameraDebugger;
    }());
    return CameraDebugger;
});
